import { CodeListService } from '../app/codelist-service';
import { EntityBaseService, IContext, HttpResponse } from 'ibiz-core';
import { IORDER1, ORDER1 } from '../../entities';
import keys from '../../entities/order1/order1-keys';
import { ORDER1DTOHelp } from '../../entities/order1/order1-dto-help';


/**
 * 订单服务对象基类
 *
 * @export
 * @class ORDER1BaseService
 * @extends {EntityBaseService}
 */
export class ORDER1BaseService extends EntityBaseService<IORDER1> {
    protected get keys(): string[] {
        return keys;
    }
    protected SYSTEMNAME = 'ActiveTYYW';
    protected APPNAME = 'App2';
    protected APPDENAME = 'ORDER1';
    protected APPWFDENAME = 'ORDER1';
    protected APPDENAMEPLURAL = 'ORDER1s';
    protected dynaModelFilePath:string = 'PSSYSAPPS/App2/PSAPPDATAENTITIES/ORDER1.json';
    protected APPDEKEY = 'order1id';
    protected APPDETEXT = 'order1name';
    protected quickSearchFields = ['order1name',];
    protected selectContextParam = {
        customer: 'customerid',
    };

    constructor(opts?: any) {
        super(opts, 'ORDER1');
    }

    newEntity(data: IORDER1): ORDER1 {
        return new ORDER1(data);
    }

    /**
     * ChangeType
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async ChangeType(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}/changetype`, _data);
        res.data = await this.afterExecuteAction(_context,res?.data,'ChangeType');
            return res;
        }
        if (_context.saleplatform && _context.order1) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}/changetype`, _data);
        res.data = await this.afterExecuteAction(_context,res?.data,'ChangeType');
            return res;
        }
        const res = await this.http.get(`/order1s/${encodeURIComponent(_context.order1)}/changetype`, _data);
        res.data = await this.afterExecuteAction(_context,res?.data,'ChangeType');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Create
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Create(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && true) {
        _data = await this.beforeExecuteAction(_context,_data,'Create');
            if (!_data.srffrontuf || _data.srffrontuf != 1) {
                _data[this.APPDEKEY] = null;
            }
            if (_data.srffrontuf != null) {
                delete _data.srffrontuf;
            }
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/customers/${encodeURIComponent(_context.customer)}/order1s`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        if (_context.saleplatform && true) {
        _data = await this.beforeExecuteAction(_context,_data,'Create');
            if (!_data.srffrontuf || _data.srffrontuf != 1) {
                _data[this.APPDEKEY] = null;
            }
            if (_data.srffrontuf != null) {
                delete _data.srffrontuf;
            }
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        _data = await this.beforeExecuteAction(_context,_data,'Create');
        if (!_data.srffrontuf || _data.srffrontuf != 1) {
            _data[this.APPDEKEY] = null;
        }
        if (_data.srffrontuf != null) {
            delete _data.srffrontuf;
        }
    _data = await ORDER1DTOHelp.get(_context,_data);
        const res = await this.http.post(`/order1s`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Finish
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Finish(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
            _data =  await this.executeAppDELogic('finish',_context,_data);
            return new HttpResponse(_data, {
                ok: true,
                status: 200
            });
        }catch (error) {
            return new HttpResponse({message:error.message}, {
                ok: false,
                status: 500,
            });
        }
    }
    /**
     * Get
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Get(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'Get');
            return res;
        }
        if (_context.saleplatform && _context.order1) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'Get');
            return res;
        }
        // const res = await this.http.get(`/order1s/${encodeURIComponent(_context.order1)}`, _data);
        // res.data = await ORDER1DTOHelp.set(_context,res.data);
        // res.data = await this.afterExecuteAction(_context,res?.data,'Get');
        // return res;
        return new HttpResponse({
            order1id:'1111',
            order1name:'1111'
        }, {
            ok: true,
            status: 200
        });
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * GetAggData
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async GetAggData(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}/getaggdata`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'GetAggData');
            return res;
        }
        if (_context.saleplatform && _context.order1) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}/getaggdata`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'GetAggData');
            return res;
        }
        const res = await this.http.get(`/order1s/${encodeURIComponent(_context.order1)}/getaggdata`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'GetAggData');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * GetDraft
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async GetDraft(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && true) {
            _data[this.APPDENAME?.toLowerCase()] = undefined;
            _data[this.APPDEKEY] = undefined;
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/getdraft`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        if (_context.saleplatform && true) {
            _data[this.APPDENAME?.toLowerCase()] = undefined;
            _data[this.APPDEKEY] = undefined;
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/getdraft`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        _data[this.APPDENAME?.toLowerCase()] = undefined;
        _data[this.APPDEKEY] = undefined;
        const res = await this.http.get(`/order1s/getdraft`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Init
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Init(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
            _data =  await this.executeAppDELogic('initData',_context,_data);
            return new HttpResponse(_data, {
                ok: true,
                status: 200
            });
        }catch (error) {
            return new HttpResponse({message:error.message}, {
                ok: false,
                status: 500,
            });
        }
    }
    /**
     * NextAction
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async NextAction(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
            _data =  await this.executeAppDELogic('NextAction',_context,_data);
            return new HttpResponse(_data, {
                ok: true,
                status: 200
            });
        }catch (error) {
            return new HttpResponse({message:error.message}, {
                ok: false,
                status: 500,
            });
        }
    }
    /**
     * PreAction
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async PreAction(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
            _data =  await this.executeAppDELogic('PreAction',_context,_data);
            return new HttpResponse(_data, {
                ok: true,
                status: 200
            });
        }catch (error) {
            return new HttpResponse({message:error.message}, {
                ok: false,
                status: 500,
            });
        }
    }
    /**
     * Remove
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Remove(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
            const res = await this.http.delete(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}`);
            return res;
        }
        if (_context.saleplatform && _context.order1) {
            const res = await this.http.delete(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}`);
            return res;
        }
        const res = await this.http.delete(`/order1s/${encodeURIComponent(_context.order1)}`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * TestEval
     *
     * @param {*} [context={}]
     * @param {*} [data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async TestEval(context: any = {}, data: any = {}): Promise<HttpResponse> {
        eval(`console.log(data.bz)`);
        return new HttpResponse(data, {
            ok: true,
            status: 200,
        });
    }
    /**
     * Update
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Update(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
        _data = await this.beforeExecuteAction(_context,_data,'Update');
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.put(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        if (_context.saleplatform && _context.order1) {
        _data = await this.beforeExecuteAction(_context,_data,'Update');
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.put(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        _data = await this.beforeExecuteAction(_context,_data,'Update');
    _data = await ORDER1DTOHelp.get(_context,_data);
        const res = await this.http.put(`/order1s/${encodeURIComponent(_context.order1)}`, _data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchAggDataSet
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async FetchAggDataSet(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && true) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/fetchaggdataset`, _data);
        res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchAggDataSet');
            return res;
        }
        if (_context.saleplatform && true) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/fetchaggdataset`, _data);
        res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchAggDataSet');
            return res;
        }
        // const res = await this.http.get(`/order1s/fetchaggdataset`, _data);
        // res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        // res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchAggDataSet');
        // return res;
        return new HttpResponse([
            {
                order1id:'1111',
                order1name:'1111'
            },
            {
                order1id:'2222',
                order1name:'2222'
            },
            {
                order1id:'3333',
                order1name:'3333'
            }
        ], {
            ok: true,
            status: 200
        });
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchDefault
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async FetchDefault(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && true) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/fetchdefault`, _data);
        res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchDefault');
            return res;
        }
        if (_context.saleplatform && true) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/fetchdefault`, _data);
        res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchDefault');
            return res;
        }
        // const res = await this.http.get(`/order1s/fetchdefault`, _data);
        // res.data = await ORDER1DTOHelp.ToDataObjArray(_context,res.data);
        // res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchDefault');
        // return res;
        return new HttpResponse([
            {
                order1id:'1111',
                order1name:'1111'
            },
            {
                order1id:'2222',
                order1name:'2222'
            },
            {
                order1id:'3333',
                order1name:'3333'
            }
        ], {
            ok: true,
            status: 200
        });
            } catch (error) {
                return this.handleResponseError(error);
            }
    }

    protected async executeAppDELogic(tag: string, _context: any, _data: any) {
        return {
            page:1,
            size:20
        }
    }

    /**
     * Select
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof ORDER1Service
     */
    async Select(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        if (_context.customer && _context.order1) {
            const res = await this.http.get(`/customers/${encodeURIComponent(_context.customer)}/order1s/${encodeURIComponent(_context.order1)}/select`);
            return res;
        }
        if (_context.saleplatform && _context.order1) {
            const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/order1s/${encodeURIComponent(_context.order1)}/select`);
            return res;
        }
        const res = await this.http.get(`/order1s/${encodeURIComponent(_context.order1)}/select`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }

    /**
     * ChangeTypeBatch接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ORDER1ServiceBase
     */
    public async ChangeTypeBatch(_context: any = {},_data: any = {}): Promise<HttpResponse> {
        if(_context.customer && true){
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/customers/${_context.customer}/order1s/changetypebatch`,_data);
            return res;
        }
        if(_context.saleplatform && true){
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/saleplatforms/${_context.saleplatform}/order1s/changetypebatch`,_data);
            return res;
        }
    _data = await ORDER1DTOHelp.get(_context,_data);
        const res = await this.http.post(`/order1s/changetypebatch`,_data);
        return res;
    }

    /**
     * GetAggDataBatch接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ORDER1ServiceBase
     */
    public async GetAggDataBatch(_context: any = {},_data: any = {}): Promise<HttpResponse> {
        if(_context.customer && true){
            const res = await this.http.post(`/customers/${_context.customer}/order1s/getaggdatabatch`,_data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        if(_context.saleplatform && true){
            const res = await this.http.post(`/saleplatforms/${_context.saleplatform}/order1s/getaggdatabatch`,_data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
            return res;
        }
        const res = await this.http.post(`/order1s/getaggdatabatch`,_data);
        res.data = await ORDER1DTOHelp.set(_context,res.data);
        return res;
    }

    /**
     * SaveBatch接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ORDER1ServiceBase
     */
    public async SaveBatch(_context: any = {},_data: any = {}): Promise<HttpResponse> {
        if(_context.customer && true){
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/customers/${_context.customer}/order1s/savebatch`,_data);
            return res;
        }
        if(_context.saleplatform && true){
    _data = await ORDER1DTOHelp.get(_context,_data);
            const res = await this.http.post(`/saleplatforms/${_context.saleplatform}/order1s/savebatch`,_data);
            return res;
        }
    _data = await ORDER1DTOHelp.get(_context,_data);
        const res = await this.http.post(`/order1s/savebatch`,_data);
        return res;
    }
}
